package com.speechb.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.speechb.common.codec.Md5Utils;
import com.speechb.common.text.TextUtil;
import com.speechb.common.text.UnicodeUtil;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.io.*;

/**
 * @author : llj
 * @version :2.1.0
 * @date : 2020/3/25 20:52
 */
public class HtmlTest2 {
    @Test
    public void test() {
       String test = getString1();
        String[] split = test.split("\\d{1,3}[、|.]");
        for (String s : split) {
            s = s.replaceAll("[ |“|”|　]","");
            if(StringUtils.isNotEmpty(s)||StringUtils.equals("<br/>",s)) {
                while (s.contains("<br/><br/>")) {
                    s = s.replaceAll("<br/><br/>","<br/>");
                }
                while (s.endsWith("<br/>")) {
                    s = TextUtil.replaceLast(s,"<br/>","");
                }
                System.out.println(s);
                System.out.println("-----------------------");
            }
        }
    }
    public static String getString1()  {
        try {

            String fileName ="C:\\Users\\A\\Desktop\\test.txt";
            InputStreamReader isr = null;
            isr = new InputStreamReader(new FileInputStream(new File(fileName)),"GBK");


            BufferedReader bufferedReader = new BufferedReader(isr);
            StringBuilder sb = new StringBuilder();
            String line = null;
            line = bufferedReader.readLine();
            sb.append(line);
            while (line!=null){
                line = bufferedReader.readLine();
                if(line != null) {
                    sb.append(line);
                }
            }

            bufferedReader.close();
            isr.close();
            return sb.toString();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    @Test
    public void test3() {
        JSONObject object = JSON.parseObject(getString1());
        JSONArray data = object.getJSONArray("data");
        JSONObject obj;
        JSONArray array;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < data.size(); i++) {
            obj = data.getJSONObject(i);
            System.out.println(obj.getString("title"));
            array = obj.getJSONArray("content");
            for (int j = 0,jlen = array.size(); j < jlen; j++) {
                sb.append(array.getJSONObject(j).getString("value"));
                if (j < jlen - 1) {
                    sb.append("<br/>");
                }
            }
            //System.out.println(sb.toString());
            sb.setLength(0);
        }
        System.out.println(UnicodeUtil.unicodeToGbk("\\u804a\\u4ec0\\u4e48\\u5462"));
    }

    @Test
    public void test14() {
        String test = "舔狗日记02月20日晴 你说生孩子本来就够痛苦了 还管是谁的干嘛呢 我可以跟你的孩子姓";
        System.out.println(test.split(" ", 2)[1]);
    }

    @Test
    public void test4() {
        String encrypt = Md5Utils.md5("ab6934108703!" + "root", 3);Md5Utils.md5("ab6934108703" + "root", 3);
        System.out.println(encrypt);
    }
}
